"""
内容：权限管理模块中角色管理公共方法
作者：陈园
"""
from ECshop.common.base import create_browser_op, create_browser, Base


# 创建一个类
class Pagerole(Base):
    # 定义属性
    url = 'http://localhost:8080/ecshop/admin/privilege.php?act=login'
    url2 = 'http://localhost:8080/ecshop/admin/index.php'
    """定义定位器"""
    permissions = ('class name', 'icon-priv')
    role_management = ('css selector', 'a[href="role.php?act=list"]')
    right = ('css selector', 'a[href="role.php?act=add"]')
    username = ('name', 'user_name')
    describe = ('name', 'role_describe')
    confirm = ('css selector', 'input[value=" 保存 "]')
    get_text = ('xpath', '//*[@id="list-table"]/tbody/tr[2]/td[2]')
    edit = ('css selector', 'a[title="编辑"]')
    edit_username = ('name', 'user_name')
    edit_describe = ('name', 'role_describe')
    edit_confirm = ('css selector', '#list-table > tbody > tr:nth-child(14) > td > input:nth-child(2)')
    get_confirm = ('css selector', 'td[style="font-size: 14px; font-weight: bold"]')
    # 定义方法

    """获取主页"""

    def page_login_open_wb2(self):
        self.base_open_web(self.url2)

    """进入iframe"""

    def page_in_iframe(self, num):
        self.base_in_frame(num)

    """退出iframe"""

    def page_quit_iframe(self):
        self.base_quit_frame()

    """点击权限管理"""

    def page_interface_perm(self):
        self.base_click(self.permissions)

    """点击角色管理"""

    def page_role_management(self):
        self.base_click(self.role_management)

    """点击添加角色"""

    def page_role_right(self):
        self.base_click(self.right)

    """输入角色名"""

    def page_role_username(self, your_content):
        self.base_input_content(self.username, your_content)

    """输入角色描述 """

    def page_role_describe(self, your_content):
        self.base_input_content(self.describe, your_content)

    """点击保存"""

    def page_role_submit(self):
        self.base_click(self.confirm)

    """获取文本"""

    def page_role_get_text(self):
        return self.base_get_text(self.get_text)

    """退出浏览器"""

    def page_role_quit(self):
        self.base_quit()

    """点击编辑按钮"""

    def page_role_click_edit(self):
        self.base_click(self.edit)

    """角色框清空"""

    def page_role_input_clear(self):
        self.base_input_clear(self.edit_username)

    """编辑角色名"""

    def page_role_edit_name(self, your_content):
        self.base_input_content(self.edit_username, your_content)

    """描述框清空"""

    def page_role_input_clear2(self):
        self.base_input_clear(self.edit_describe)

    """编辑角色描述"""

    def page_role_edit_describe(self, your_content):
        self.base_input_content(self.edit_describe, your_content)

    """点击保存"""

    def page_role_click_confirm(self):
        self.base_click(self.edit_confirm)

    """获取编辑成功页面文本"""

    def page_role_get_confirm_text(self):
        return self.base_get_text(self.get_confirm)
